﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;


namespace SF.Web.UI.mallCs
{
    public class orderDetail
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    usingMsg = "<link href='css/orderdetail.css' rel='stylesheet' />";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    jsMsg = "$(document).ready(function () {if ($('#payNow').attr('isPay') == 'true') {$('#payNow').text('已支付');$('#getGoodsAddress').text('');$('#payNow').css('background-color', '#626670');$('#payNow').css('border-color', '#626670');$('#payNow').text('已支付');} else {$('#payNow').css('background-color', 'rgb(240, 35, 135)');$('#payNow').css('border-color', 'rgb(240, 35, 135)');$('#payNow').text('去支付');}});function orderBuy(orderId) {if ($('#payNow').text() == '已支付') {return;}var addre = $('#getGoodsAddress').attr('addressid');if (addre == '') {alert('请先选择收货地址！');return;}location.href = '/api/paypage.aspx?orderId=' + orderId;}";
                }
            }
            return jsMsg;
        }

        public string loaddingHtml(Model.sf_user_info userInfo, string parm1, string parm2, string templateType)
        {
            string htmlMsg = "",appWhere="";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                    string orderMsg = "", goodsMsg = "", addressMsg = "", priceMsg = "", orderID = "", payNow = "", addressid = "";
                    BLL.sf_goods_info goodBll = new BLL.sf_goods_info();
                    BLL.sf_goods_amounts amountBll = new BLL.sf_goods_amounts();
                    BLL.sf_goods_color colorBll = new BLL.sf_goods_color();
                    BLL.sf_goods_size sizeBll = new BLL.sf_goods_size();
                    BLL.sf_goods_order orderInfoBll = new BLL.sf_goods_order();
                    BLL.sf_goods_orderdetal orderDatalBll = new BLL.sf_goods_orderdetal();
                    BLL.sf_user_address addressBll = new BLL.sf_user_address();
                    int type = Convert.ToInt32(parm2);

                    Model.sf_goods_order order = orderInfoBll.GetModel("orderNum='" + parm1 + "' and userNum='" + userInfo.userNum + "' and " + appWhere);
                    //标签 订单信息
                    orderMsg = "<div class='orderlisttit'>订单号：" + order.orderNum + "</div><div class='orderdeatilbox clearfix'><div class='o_d_info'><p>订单状态：<em class='o_d_sign'>" + (order.isPay.ToString() == "1" ? "未支付" : "完成支付") + "</em></p><p>支付方式：<em>" + (order.payWay.ToString() == "1" ? "微支付" : "在线付款") + "</em></p><p>下单时间：<em>" + order.addTime + "</em></p></div></div>";
                    orderID = order.orderNum;
                    //价格信息 属性
                    int? goodsNum = 0; decimal? goodsMoney = 0;

                    //获取 商品信息
                    List<Model.sf_goods_orderdetal> lists = orderDatalBll.GetModelList("orderNum='" + parm1 + "' and " + appWhere);
                    //标签 商品信息
                    for (int i = 0; i < lists.Count; i++)
                    {
                        Model.sf_goods_info good = goodBll.GetModel("goodsNum='" + lists[i].goodsNum + "' and " + appWhere);
                        Model.sf_goods_amounts amount = amountBll.GetModel(Convert.ToInt64(lists[i].amountId));
                        if (amount!=null)
                        {
                            string size = sizeBll.GetModel(Convert.ToInt64(amount.sizeId)).sizeName;
                            string color = colorBll.GetModel(Convert.ToInt64(amount.colorId)).colorName;
                            goodsMsg += "<div class='orderdeatil clearfix'><a href='detailed.aspx?id=" + good.id + "'><img src='" + good.showImgs + "' class='fl' height='101' width='80'><div class='user_orderlist_r'><p class='cart_g_name'>" + good.names + "</p><p class='space10'></p><p class='g_d_price'>￥" + lists[i].totalMoney + "</p><p><span class='fl'>单价：￥" + lists[i].price + "</span><span class='fr'>数量：" + lists[i].numbers + "</span></p><p><span class='fl'>尺码：" + size + "</span><span class='fr'>颜色：" + color + "</span></p></div></a></div>";
                        }
                        else
                        {
                            goodsMsg += "<div class='orderdeatil clearfix'><a href='detailed.aspx?id=" + good.id + "'><img src='" + good.showImgs + "' class='fl' height='101' width='80'><div class='user_orderlist_r'><p class='cart_g_name'>" + good.names + "</p><p class='space10'></p><p class='g_d_price'>￥" + lists[i].totalMoney + "</p><p><span class='fl'>单价：￥" + lists[i].price + "</span><span class='fr'>数量：" + lists[i].numbers + "</span></p></div></a></div>";
                        }
                        goodsNum += lists[i].numbers;
                        goodsMoney += lists[i].totalMoney;
                    }
                    //标签 地址信息
                    if (!string.IsNullOrEmpty(order.addressText))
                    {
                        //获取 地址信息
                        string[] strs = order.addressText.Split(',');
                        addressid = "1";
                        addressMsg += "<div class='orderdeatilbox or_price clearfix'><p><span class='tit_h'>收货人：</span>" + strs[0] + "</p><p><span class='tit_h'>手机：</span>" + strs[1] + "</p><p><span class='tit_h'>收货地址：</span>" + strs[2] + "</p></div>";
                    }
                    else
                    {
                        addressMsg = "<div class='orderdeatilbox or_price clearfix'>无收货地址信息</div>";
                    }
                    //标签 价格信息
                    priceMsg += "<div class='orderdeatilbox or_price clearfix'><p><span class='tit_h'>订单总件数：</span>" + goodsNum + " 件</p><p><span class='tit_h'>商品总金额：</span>¥" + goodsMoney + "</p><p><span class='tit_h'>订单应付金额：</span><span class='arial font16'>¥" + goodsMoney + "</span></p></div>";
                    payNow = type > 1 ? "true" : "false";
                    htmlMsg = "<body><form id='form1' runat='server'><header id='header' class='u-header clearfix'><div class='u-hd-left f-left'><a href='javascript:history.back();' class='J_backToPrev'><span class='u-icon-px i-hd-back'></span></a></div><div class='u-hd-tit'><span>订单详情</span></div><div class='u-hd-right f-right'><a href='index.aspx'><span class='u-icon-px i-hd-home'></span></a></div></header><div class='space10'></div><div class='userdiv'>" + orderMsg + "</div><div class='userdiv'><div class='orderlisttit'>商品详情</div><div class='orderdeatilbox clearfix'>" + goodsMsg + "</div></div><div class='userdiv'><div class='orderlisttit'>收货信息<span class='c-grey prf05'></span><a href='address.aspx?orderId=" + orderID + "' id='getGoodsAddress' addressid='" + addressid + "' style='float:right;'>管理收货地址</a></div>" + addressMsg + "</div><div class='userdiv'><div class='orderlisttit'>价格详情</div>" + priceMsg + "</div><div style='width:100%;height:60px;'></div><div class='navbar navbar-default navbar-fixed-bottom'><div class='container nav-current-box'><button id='payNow' type='button' name='afresh-check' class='btn btn-long btn-purple' data-mars_sead='user_order_detail_list_pay_btn' data-page='detail' data-order_sn='15052082067746' isPay='" + payNow + "' data-loading-text='提交中...' onclick=\"orderBuy('" + orderID + "')\">去支付</button></div></div><a href='#top' class='u-backtop'><span class='u-icon i-backtop'></span></a></form></body>";
                }
            }
            return htmlMsg;
        }
    }
}
